Skip to main content

Overview

This module provides global configuration settings for PVAC-HFHE, primarily focused on debug output control. The debug level can be configured via environment variables or programmatically.

Global variables

g_dbg

Global debug level variable.
int
Current debug level (0-2)
The debug level controls the verbosity of output:
Silent
No debug output
Normal
Standard debug output (default)
Verbose
Detailed debug output with additional information
The debug level is automatically initialized from environment variables on first use.

Functions

set_debug_level

Sets the global debug level programmatically.
int
Desired debug level (will be clamped to range [0, 2])
Example:
Values outside the range [0, 2] are automatically clamped to the nearest valid value.

get_debug_level

Retrieves the current debug level.
int
Current debug level (0-2)
Example:

Environment variables

PVAC_DBG

Primary environment variable for setting the debug level.
This variable is checked first during initialization.

HFHE_DBG

Fallback environment variable for backward compatibility.
If PVAC_DBG is not set, HFHE_DBG will be used instead.

Initialization

The debug level is initialized automatically on first access using the following logic:
  1. Check if PVAC_DBG environment variable is set
  2. If not, check if HFHE_DBG environment variable is set
  3. If neither is set, default to level 1 (normal)
  4. Clamp the value to the range [0, 2]
Example:

Usage patterns

Conditional debug output

Runtime configuration

Library initialization

Best practices

For library users:
  • Set the debug level early in your program’s initialization
  • Use environment variables for quick testing without recompilation
  • Set level 0 for production deployments
For library developers:
  • Use level 1 for important operations (key generation, encryption, etc.)
  • Use level 2 for detailed algorithmic steps
  • Always check the debug level before expensive string formatting

Thread safety

The debug level is stored in a global variable. Changing it from multiple threads without synchronization may result in race conditions. If thread safety is required, wrap calls to set_debug_level() in appropriate synchronization primitives.